package com.protocols.sctp.m3ua.sccp.tcap.camel;

import java.io.Serializable;

import com.protocols.BCDNumber;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.tcap.TcapBegin;
import com.protocols.sctp.m3ua.sccp.tcap.TcapConstructor;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitByteArray;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitNumber;

public class CamelReleaseCall extends CamelInvoke implements Serializable{
	
	//private TcapConstructor Details = new TcapConstructor(0x04); 
	private TcapPrimitiveUnitByteArray EventCause = new TcapPrimitiveUnitByteArray(0x04);
	
	public CamelReleaseCall() {
		super();		
		setOpCode(22,true);	// Releasecall
		super.Invoke.addElement(EventCause);
		//Details.addElement(EventCause);
	}
		
	
	
	public TcapConstructor getRootComponent(){
		return Invoke;
	}
	
	public int getCauseLocation(){
		
		return (EventCause.getTagValue()[0] & 0b00001111);
	}

	public int getCodingStandard(){
		
		return (EventCause.getTagValue()[0] & 0b01100000)>>5;
	}
	
	public int getExtension1(){
		
		if (isExtension1Available()){
			return (EventCause.getTagValue()[1] & 0xff);
		}
		return 0;
	}

	public Boolean isExtension1Available(){
		
		return ((EventCause.getTagValue()[0] & 0xff) >=80);
	}
	
	public int getCause(){
		if (isExtension1Available()){
			return (EventCause.getTagValue()[2] & 0x7f);
		}	
		return (EventCause.getTagValue()[1] & 0x7f);
	}

	public int getExtension2(){
		if (isExtension1Available() && isExtension2Available()){
			return (EventCause.getTagValue()[3] & 0xff);
		}
		else if (!isExtension1Available() && isExtension2Available()){
			return (EventCause.getTagValue()[2] & 0xff);
		}
		return 0;
		
	}

	public Boolean isExtension2Available(){
		
		if (isExtension1Available())
			return ((EventCause.getTagValue()[2] & 0xff) >=80);
		else
			return ((EventCause.getTagValue()[1] & 0xff) >=80);
	}

	public void setCause(int causelocation, int codingstandard, int cause){  
		
		EventCause.setTagValue(new byte[] {(byte)(0x80|(codingstandard<<5)|causelocation),(byte)(0x80|cause)});
}
	
	
}
